package com.example.json.controller;

import com.example.json.model.UserModel;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.catalina.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.jws.soap.SOAPBinding;



@Controller
public class UserController {

    @GetMapping("/test1")
    @ResponseBody
    public UserModel test1(){
        UserModel user = new UserModel();
        user.setName("zhangsan");
        user.setAge(20);

        return user;
    }

    @GetMapping("/test2")
    @ResponseBody
    public String test2(){
        UserModel user = new UserModel();
        user.setName("lisi");
        user.setAge(21);

        ObjectMapper objectMapper = new ObjectMapper();
        String result = "";
        try {
             result = objectMapper.writeValueAsString(user);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return result;
    }
}
